package com.kaifamiao.jdbc.features;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;

public class SendBatch1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        /*
        String driverClassName = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/kaifamiao?serverTimezone=Asia/Chongqing";
        String username = "kfm";
        String password = "kfm";
        */

        String driverClassName = "oracle.jdbc.OracleDriver";
        String url = "jdbc:oracle:thin:@localhost:1521:kaifamiao";
        String username = "kaifamiao";
        String password = "kaifamiao";

        Class.forName( driverClassName );
        Connection conn = DriverManager.getConnection( url, username, password );

        Statement stmt = conn.createStatement();

        String sql1 = "INSERT INTO t_pandas ( id , name ) VALUES ( 3001, '星星' )";
        stmt.addBatch( sql1 );

        String sql2 = "INSERT INTO t_pandas ( id , name ) VALUES ( 3002, '灵灵' )";
        stmt.addBatch( sql2 );

        String sql3 = "DELETE FROM t_pandas WHERE name LIKE '%美'";
        stmt.addBatch( sql3 );

        // 批量"执行"SQL语句
        // 1、发送一批SQL语句给数据库服务器
        // 2、接收一批由数据库返回的结果
        int[] counts = stmt.executeBatch();
        System.out.println( Arrays.toString( counts ) );

        stmt.close();
        conn.close();
    }
}
